package com.teacher.pc.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.teacher.common.CommonResult;
import com.teacher.pojo.dto.classteacher.ClassTeacherAddDto;
import com.teacher.pojo.dto.classteacher.ClassTeacherGetDto;
import com.teacher.pojo.dto.classteacher.ClassTeacherUpdateDto;
import com.teacher.pojo.vo.classteacher.ClassTeacherGetVo;
import com.teacher.pojo.vo.classteacher.ClassTeacherListVo;
import com.teacher.service.IClassTeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zfm
 * @since 2021-07-18
 */
@RestController
@RequestMapping("/pc/class-teacher")
public class ClassTeacherController {

    @Autowired
    private IClassTeacherService iClassTeacherService;

    /**
     * 添加班主任
     *
     * @param dto
     * @return
     */
    @ApiOperation("添加班主任 classTeacher_add")
    @PostMapping
    @PreAuthorize("hasAuthority('classTeacher_add')")
    public CommonResult<String> add(@RequestBody ClassTeacherAddDto dto) {
        return iClassTeacherService.add(dto);
    }

    /**
     * 删除班主任班级关联
     *
     * @param ids
     * @return
     */
    @ApiOperation("删除班主任班级关联 classTeacher_delete")
    @DeleteMapping
    @PreAuthorize("hasAuthority('classTeacher_delete')")
    public CommonResult<String> del(@RequestBody List<Long> ids) {
        iClassTeacherService.removeByIds(ids);
        return CommonResult.success("删除成功");
    }

    /**
     * 查询班主任班级关联信息
     *
     * @param dto
     * @return
     */
    @GetMapping
    @ApiOperation("查询班主任班级关联信息 classTeacher_get")
    @PreAuthorize("hasAuthority('classTeacher_get')")
    public CommonResult<IPage<ClassTeacherGetVo>> get(ClassTeacherGetDto dto) {
        return iClassTeacherService.get(dto);
    }

    /**
     * 更新班主任班级关联信息
     *
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation("更新班主任班级关联信息 classTeacher_update")
    @PreAuthorize("hasAuthority('classTeacher_update')")
    public CommonResult<String> update(@RequestBody ClassTeacherUpdateDto dto) {
        return iClassTeacherService.put(dto);
    }


    /**
     * 班主任查询班级
     *
     * @return
     */
    @GetMapping("/byTeacherKey")
    @ApiOperation("班主任查询班级")
    public CommonResult<List<ClassTeacherListVo>> getClassTeacherList() {
        return iClassTeacherService.getClassTeacherList();
    }

}

